package com.rpc.implementsc;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Db;
import com.rpc.interfacec.GoodsService;
import com.service.Commonmethod;
import io.jboot.aop.annotation.Bean;
import io.jboot.core.rpc.annotation.JbootrpcService;

import javax.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;




@JbootrpcService
public class GoodsServiceImpl  implements GoodsService {
    private com.model.Goods goodsobj = new com.model.Goods();
    private com.model.GoodsCollect goodscollect = new com.model.GoodsCollect();

    public String hello(String name){
        System.out.println("hello" + name);
        return "hello ok";
    }

//
//    public boolean likeandcollect(Integer pgoods_id) {
//        Integer goods_id = pgoods_id;
//        com.model.Goods  goods = goodsobj.dao.findById(goods_id);
//        System.out.println(goods);
//        Integer rand_user_id=  Commonmethod.getuserid();
//        System.out.println(rand_user_id);
//        if(rand_user_id>0){
//            // 获取user的name属性
//            Integer user_id = goods.getInt("user_id");
//            long add_time  =System.currentTimeMillis()/1000;
//            Map map = new HashMap();
//            map.put("user_gooods_id", user_id);
//            map.put("user_id", rand_user_id);
//            map.put("goods_id", goods_id);
//            map.put("add_time", add_time);
//            System.out.println(goodscollect.use("a1").put(map).save());
//            //   System.out.println(goodscollect.us.put(map).save());
//            Random rand = new Random();
//            int randNumber =rand.nextInt(10) + 1;
//            System.out.println(Db.update(" UPDATE tp_goods SET click_count=click_count+"+randNumber+" WHERE goods_id="+goods_id));
//        }
//        return true;
//    }
}
